package com.easyCode.sqlMapper.renderHandler;

import cn.hutool.extra.spring.SpringUtil;
import com.easyCode.sqlManager.GlobalProperties;
import com.easyCode.sqlMapper.mapInfo.TableMapInfo;
import com.easyCode.sqlMapper.template.RenderHandler;
import com.easyCode.sqlMapper.template.SqlTemplateConfig;
import com.easyCode.sqlMapper.template.TemplateContext;
import org.apache.velocity.VelocityContext;

import java.util.Locale;

/**
 * controller层渲染参数准备
 *
 * @author 大忽悠
 * @create 2022/12/3 17:45
 */
public class ControllerRenderHandler implements RenderHandler<VelocityContext> {

    @Override
    public String paramPrepare(VelocityContext velocityContext, TableMapInfo tableMapInfo, SqlTemplateConfig sqlTemplateConfig, TemplateContext templateContext) {
        velocityContext.put("packagePath", sqlTemplateConfig.getControllerModuleName());
        velocityContext.put("className",tableMapInfo.getTableName());
        velocityContext.put("classNameDto",tableMapInfo.getTableName()+"Dto");
        velocityContext.put("serviceModule",sqlTemplateConfig.getServiceModuleName());
        velocityContext.put("voModule",sqlTemplateConfig.getVoModuleName());
        velocityContext.put("dtoModule",sqlTemplateConfig.getDtoModuleName());
        velocityContext.put("cacheFeature", SpringUtil.getBean(GlobalProperties.class).getFeature().getCache());
        templateContext.setVal(TemplateContext.JAVA_FILE_NAME,tableMapInfo.getTableName()+"Controller.java");

        return sqlTemplateConfig.getControllerModuleName();
    }
}
